/**
 * Created by dell on 2017/2/23.
 */
$(function () {
  	var bdbChangeLog = {
		/* 初始数据 */
		defData: {
			pageSize: 20,
			ip_Id: bdbMain.getUrlParams().id
		},

		/* 页面状态 */
		pageState: {
			page: 1
		},

	  	/* 列表 */
	  	list: function(obj) {
		  	var _this = this,
			obj = obj || {page: 1};

			_this.pageState.page = obj.page;
			bdbMain.mLRManag({mask: true, loading: true});
			$.post('/ServerIp/ipLogList', {
				id: _this.defData.ip_Id,
				pageNumber: _this.pageState.page,
				pageSize: _this.defData.pageSize
			},function(response) {
				if (response.code == 0) {
					var listHtml =_this.listProc(response.data.list),
						totalRowCont = response.data.totalCount;
						$('.bdb-list').html(listHtml);

					bdbMain.mLSleep({mask: false, loading: false});
					$('#js-bdb-creatPage').bdbPagination({
						totalRowCnt : totalRowCont,
						currentPage : _this.pageState.page,
						pageSize : _this.defData.pageSize
					});

					$('.bdb-record-cnt').html(bdbMain.pageInfo.recordCnt.replace('{cnt}',totalRowCont));
				} else {
					bdbMain.mLSleep({partMask: false, loading: false, alert: {type: 2, msg: response.msg}});
				}
			});
		},

	  	/* 列表模板 */
	  	listProc: function(data) {
		  	var tplHtml = '';
		  	$.each(data,function (index, value) {
				tplHtml += '<div class="bdb-list-row" data-id="' + value.log_id + '">\
							  <div class="bdb-mx-w-col1 bdb-ellipsis">' + value.log_id + '</div>\
							  <div class="bdb-mx-w-col2 bdb-ellipsis">' + value.real_name + '</div>\
							  <div class="bdb-mx-w-col3 bdb-ellipsis">' + value.time + '</div>\
							  <div class="bdb-mx-w-col4 bdb-ellipsis">' + value.operate_type + '</div>\
							  <div class="bdb-mx-w-col5 bdb-ellipsis">' + value.detail + '</div>\
							  </div>';
			});
		  	return tplHtml;
		},

		/* 加载分页 */
		pageEvent: function() {
			var _this = this;
			$('.bdb-creatPage').off('click').on('click', '.bdb-pagination', function(e) {
				e.preventDefault();
				var page = parseInt($(e.target).text());
				if (!isNaN(page)) {
					_this.list({page: page});
				}
			});
		},

	  	/* 屏幕自适应高度 */
		contentSizeResize: function() {
			$(window).resize(function () {
				$('.bdb-list').bdbScreenH(1);
			});
		},

  	  	init: function() {
		    var _this = this;

		    _this.list();
		    _this.pageEvent();
		    _this.contentSizeResize();

		    $('.bdb-list').bdbScreenH(2);
		}
	};

  	bdbChangeLog.init();
});